package com.nercel.dsj.gksales.model;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.nercel.dsj.gksales.constant.Const;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 通用查询参数封装
 * @author sunlin
 * @date 2018-10-30
 */
@Data
@ApiModel(value = "查询参数")
public class QueryParams {

    @ApiModelProperty(hidden = true)
    private int pageNumber = 1;

    @ApiModelProperty(hidden = true)
    private int pageSize = Const.PAGE_SIZE;

    @ApiModelProperty(hidden = true)
    private String sort;

    @ApiModelProperty(hidden = true)
    private Map<String, Object> params = new HashMap<>();

    public void put(String key, Object value) {
        params.put(key, value);
    }

    public Object get(String key) {
        return params.get(key);
    }

    @SuppressWarnings("unchecked")
    public void putAll(Object beanObject) {
        ObjectMapper objectMapper = new ObjectMapper();
        params = objectMapper.convertValue(beanObject, Map.class);
    }

    public QueryParams(){}

    public QueryParams(Object bean){
        this.putAll(bean);
    }

}
